package com.pingan.factory;

import org.quartz.*;
import org.quartz.impl.StdSchedulerFactory;

public class TimerFactory {

    public void instanceJob(Class<Job> classType,String cron) throws SchedulerException {
        Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler();
        scheduler.getContext().put("sKey", "sValue");

        //创建一个trigger
        CronTrigger trigger = TriggerBuilder.newTrigger()
                .withSchedule(CronScheduleBuilder.cronSchedule(cron)).build();

        //创建一个job
        JobDetail jobDetail = JobBuilder.newJob(classType).build();

        scheduler.scheduleJob(jobDetail, trigger);
        scheduler.start();
    }
}
